<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="/css/font.css">
		<link rel="stylesheet" href="/css/xadmin.css">
	</head>

	<body>
		<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="#">课程管理</a>
                <a>
                    <cite>选课结果</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);"
             title="刷新">
                <i class="layui-icon" style="line-height:30px">ဂ</i></a>
        </div>
		<div class="x-body" id="app">
			<span class="x-right" style="line-height:40px;float:left">共有数据：{{ stuCourses.length }} 条</span>
			<table class="layui-table">
				<thead>
					<tr>
						<th>课程代码</th>
                        <th>课程名称</th>
                        <th width="60">课程性质</th>
                        <th width="60">上课星期</th>
                        <th width="60">上课时间</th>
                        <th width="60">上课周期</th>
                        <th>授课教室</th>
                        <th>授课教师</th>
						<th width="50">操作</th>
				</thead>
				<tbody>
					<tr v-for="stuCourse in stuCourses">
						<td>{{ stuCourse.course_no }}</td>
                        <td>{{ stuCourse.course_name }}</td>
                        <td v-if="stuCourse.course_type == 2" >专业选修</td>
                        <td>{{ stuCourse.start_day }}</td>
                        <td>{{ stuCourse.start_time }}</td>
                        <td>{{ stuCourse.time }}</td>
                        <td>{{ stuCourse.room_name }}</td>
                        <td>{{ stuCourse.teacher_name }}</td>
						<td class="td-manage">
						    <button class="layui-btn-danger layui-btn layui-btn-sm" onclick="choose_course(this)" :data-id="stuCourse.id" :data-courseName="stuCourse.course_name" href="javascript:;"><i
                                 class="layui-icon">&#xe640;</i>退选</button>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<script type="text/javascript" src="/js/jquery.min.js"></script>
        <script type="text/javascript" src="/js/vue.min.js"></script>
        <script type="text/javascript" src="/js/xadmin.js"></script>
        <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/js/jquery.form.js"></script>
		<script>
			var vm = new Vue({
	            el : '#app',
	            data : {
	                // 学生的选课结果
	                stuCourses : ""
	            },
	            created : function() {
	                // 获取学生的选课结果
	               this.listStuCourse();
	            },
	            methods : {
	            	listStuCourse : function() {
	                    var vm = this;
	                    $.ajax({
	                        url : "/student/course/listStuCourse",
	                        type : "get",
	                        success : function(result) {
	                            if (result.state) {
	                            	vm.stuCourses = result.data;
	                            } else {
	                                layui.use(['layer'], function(){
	                                    var layer = layui.layer
	                                    layer.msg(""+result.msg, {icon: 5});
	                                });
	                            }
	                        }
	                    });
	                }
	            }
	        });

			// 退选
			function choose_course(obj) {
				var stuCourseId = $(obj).attr("data-id");
				var courseName = $(obj).attr("data-courseName");
				layer.confirm('确认要退选【'+courseName+'】吗？', function(index) {
                    $.ajax({
                         url : "/student/course/removeChooseCourse",
                         type : "post",
                         data : {
                        	 stuCourseId: stuCourseId
                         },
                         success : function(result) {
                             if (result.state) {
                                 layer.msg('退选成功!',{icon:1,time:1000});
                                 vm.listStuCourse();
                             } else {
                                 layer.msg(""+result.msg, {icon: 5});
                             }
                         }
                     });
               });
			}
		</script>
	</body>

</html>
